package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.badge.BadgeConfig;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eBadgeType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.musicroom.UserMusicRoomBeautyData;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.channelmusicroom.ChannelMusicRoomRankActivityModule;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomRankActivityModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.BadgeConfigMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.musicroom.MusicRoomLog;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获得妙音坊时辰奖励
 */
public class UseAddMusicRoomTimerReward extends BaseUseGoods {

	public UseAddMusicRoomTimerReward(GamePlayer player, GoodsInfo goodsInfo, long param) {
		super(player, goodsInfo, param);
	}

	@Override
	int checkUse(long count) {
		if (!SystemOpenMgr.systemOpen(player, eSystemId.MusicRoom.getValue())) {
			return GameErrorCode.E_SYSTEM_NO_OPEN;
		}
		List<UserMusicRoomBeautyData> livingBeautyList = player.getModule(MusicRoomModule.class).getLivingBeautyList();
		if (livingBeautyList.size() == 0) {
			return GameErrorCode.E_MUSIC_ROOM_BEAUTY_NOT_LIVE_IN;
		}
		return 0;
	}

	@Override
	UseGoodsResult executeUse(long count) {
		UseGoodsResult result = new UseGoodsResult();
		long timerAmount = goodsInfo.getParamList().get(0).longValue();
		Property timerProduce = player.getModule(MusicRoomModule.class).calcTimerCardReward(timerAmount * count);
		if (!timerProduce.isNothing()) {
			player.getModule(CurrencyModule.class).addCurrency(timerProduce, eLogMoneyType.MusicRoom, eLogMoneyType.BagUse);
		}

		player.getModule(MusicRoomRankActivityModule.class).addCardUseAmount((int) count);
		//跨域百花争艳 妙音坊冲榜
		player.getModule(ChannelMusicRoomRankActivityModule.class).addCardUseAmount((int) count);

		result.setReward(PropertyHelper.parsePropertyToString(timerProduce));

		MusicRoomLog.trackSpeedUpCardUsed(player, count);
		return result;
	}
}
